Skip to content

fix(studio-server): a file the drive never answers no longer holds a project's first copy - #8403

Merged
miguel-heygen merged 3 commits into
mainfrom
fix/history-open-deadline
Nov 21, 2026
Merged

miguel-heygen merged 3 commits into
mainfrom
fix/history-open-deadline

Conversation

@miguel-heygen

Copy link
Copy Markdown
Collaborator

What

A project's first history copy no longer waits forever on a file the drive never answers. Each file it reads gets a deadline (10 s) that starts when its read starts. A file that misses it is left owed, the way a file that is still changing is, and adoption copies it once the drive answers. The open finishes.

Why

On a drive that stops answering (it showed up on an external exFAT disk), opening a project never finished. The first copy read every file through blobs.put with no deadline, and the open waited for all of them. The app's main thread stayed free, but the project never opened.

Related work

This is the open-deadline half of #8187, split out so the freeze fix can ship on its own. #8187 keeps the part about agent steps that go ahead of a pending first copy.

What this does not fix yet: since #8375 an agent step waits for every first copy still being taken. With only this PR, a dead drive no longer blocks the open, but the first agent step still waits on that one file until #8187 lands. That is still better than main today, where the open itself never finishes.

How

  • firstOpen gives each file's copy firstCopyFileMs (option, default 10 s) from when its read starts. While a copy waits for one of the four read slots, its deadline restarts each time another first copy finishes. So healthy progress never cuts off a queued read, and a stalled read is owed 10 s after its own start. Past the deadline the file reads as "changing" and joins the owed files that adoptMediaInBackground already retries.
  • A read cannot be cancelled, so a stuck read keeps its slot. A dead drive holds the slots the first copy already allows, never more.
  • storeIfPresent reads one path at a time, so a retry of a stuck file waits behind the stuck read instead of starting a second read on the same drive.
  • A copy that lands after its deadline is kept. Adoption takes those bytes as the file's start, then one more sweep records any edit made since the open as a change. A file whose first try came back missing, still changing or failed is read again from scratch.
  • Pins. A late copy's hash is pinned in the blob store as it is filed, inside the same per-hash turn a delete takes, so a budget prune cannot drop it before adoption records it. Pinned blobs count as baseline in historyBytes(). Only the owner of a pin releases it.
  • Receipts. A late copy follows only the save receipts heard by the moment of its read. A later save that writes the original bytes back therefore cannot make the in-between bytes the start.
  • Kept bytes. The bytes a save replaced in a file still owed its first copy survive pruning until that copy is recorded. They count as start, not undo history.
  • A copy is marked reference-only (over 64 MiB, or media), so adoption never mistakes it for a lost blob, and it never reads inside the history queue.
  • Three test mocks of the blob store dropped put's arguments; they now pass the read callback through.

Package size budget

The packed @hyperframes/studio-server tarball measures 191,581 bytes against a budget of 188,871. The extra bytes are this PR's history code; no new import comes in. Following the budget file's rule (5% above measured), the packed budget is now ceil(191,581 × 1.05) = 201,161. Unpacked, 737,155 bytes, fits its budget.

Test plan

  • Unit tests added/updated
  • firstCopy.test.ts:
    • A file whose read never answers is read once, listed as owed, and the open finishes. Against main the open never resolves and the test times out at 20 s; with this PR it passes in about 140 ms.
    • A late copy keeps the original: blob filing is held past the deadline, the file is edited, then filing completes. The original is the start and the edit a change.
    • A late copy beside a stalled one: a late copy stays adopted, and kept through a 1-byte-budget prune, while another file's read stays stalled.
    • Budget and read slots: a waiting late copy never pushes an in-budget edit out of history, and rereads go 4 at a time.
    • A queued read's deadline: nine 150 ms reads through four slots, each with a 400 ms deadline, are all copied. It fails with a deadline that counts from the queue, since the last round ends at 450 ms.
    • A stalled read is not stretched: its deadline does not grow while other reads finish; the open ends within 1.5 s at a 1 s deadline.
    • Receipts: a save writing the original back over a later change keeps the original as the late copy's start. An early save's original survives a prune before its late copy is filed. Both fail on this branch's first commit.
  • blobStore.test.ts: a pinned blob survives prunes until each pin is released.
  • Each fix was broken in turn, and each break turned its own case red.
  • With everything restored, firstCopy.test.ts passed 3 times in a row, and the whole studio-server suite passed with 0 failures.
  • Manual testing performed
  • Comments follow CONTRIBUTING.md "Comments"

Not exercised: a real drive that stops answering, and native Windows. These were Linux runs with local fixtures.

…project's first history copy

Each file the first copy reads gets a deadline from when its read starts. A file that misses it is left owed and
adopted once the drive answers, keeping the bytes it read as the file's start, so the open finishes.
…ts read, kept through pruning

A late first copy follows only the save receipts heard by the moment of its read, so a later save writing the
original back cannot move the start. The bytes a save replaced in a file still owed its first copy stay through
pruning, counted as start rather than undo history, until that copy is recorded.
@github-actions

Copy link
Copy Markdown
Contributor

Edit accuracy: accurate 271 (base branch 271), smooth 62 of those

The gate passes.
Smoothness is reported in the artifact, not gated. A case fails only if it fails 2 of 3 runs.

Quarantined, measured but not gated (0)

@vanceingalls vanceingalls left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approved at cc29e5f. A file the drive never answers no longer holds the open.

  • Deadline (firstCopyOrOwed). Only queued reads have their deadline restarted. A read leaves firstCopyProgress when it gets its slot and is armed once, so a stalled read is owed 10 s after its own start and is never stretched. Queue order is FIFO, and when every slot is stuck nothing finishes, so a queued read still expires 10 s after the last finish. Timers clear in .finally.
  • Pins. A late copy's pin is taken inside the per-hash inTurn, the same turn forget uses and re-checks pins.has in, so a prune can't drop it first. It's released on adoption success, failure, gone and changing, and at open for in-deadline copies. historyBytes counts baseline, pinned and owed starts in one deduplicated set.
  • Receipts. heardAtRead is snapshotted when the bytes are verified, and a later save records as an ordinary change through the extra sweepIn(0).
  • Retries. storeIfPresent waits are bounded by the stuck read. Owed retries back off min(SETTLE_MS·2^n, 30 s), one at a time per file, on unref'd timers.
  • The five #8187 points are all addressed: the heardAtRead snapshot, onRead at byte validation, heardBeforeCopy in the prune keep-set, owedStarts in historyBytes, and receipt blobs held only while adopting.has(path).
  • The fails-without-fix line is at firstCopy.test.ts:186, and the tests use short real deadlines with no 10 s waits.

Nits:

  • In firstCopyOrOwed, a read that was owed while queued re-arms a ref'd 10 s timer when it later gets a slot, after result has settled. It does nothing, but it can hold process exit for up to 10 s. Guard it with a settled flag or unref it.
  • The queued-deadline test (400 ms deadline against 150 ms reads) could flake on a loaded runner.
  • Unpacked size is only about 0.7% under the 1% tolerance, so the next history PR will trip the budget.
  • A dead drive holds up to 4 global read slots, which delays other projects' first copies. They still open, with their files owed. That's the known limit, with #8187 to follow.

@miguel-heygen
miguel-heygen added this pull request to the merge queue Nov 21, 2026
Merged via the queue into main with commit 71dc6f2 Nov 21, 2026
82 checks passed
@miguel-heygen
miguel-heygen deleted the fix/history-open-deadline branch November 21, 2026 22:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants